// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  devtools: { enabled: true },

  // Add Pinia module
  modules: [
    '@pinia/nuxt'
  ],

  // Pinia configuration (optional)
  pinia: {
    autoImports: [
      // automatically import `defineStore`
      'defineStore', // import { defineStore } from 'pinia'
      ['defineStore', 'definePiniaStore'], // import { defineStore as definePiniaStore } from 'pinia'
    ],
  },

  // Add CSS frameworks or global CSS here if needed
  css: ['~/assets/css/main.css'], // Ensure global CSS is loaded (Tailwind needs this)

  // PostCSS configuration
  postcss: {
    plugins: {
      '@tailwindcss/postcss': {},
      autoprefixer: {},
    },
  },

  // Configure runtime environment variables
  runtimeConfig: {
    public: {
      // Exposed to the client-side
      apiBase: process.env.NUXT_PUBLIC_API_BASE || 'http://localhost:8080/api' // Default backend API URL
    }
  },

  // Configure Vite options
  vite: {
    server: {
      proxy: {
        // Proxy /api requests to the backend server during development
        '/api': {
          target: process.env.NUXT_PUBLIC_API_BASE || 'http://localhost:8080', // Use the runtime config or default
          changeOrigin: true,
          // Optional: Rewrite path if your backend expects '/api' prefix removed
          // rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  },

  // Enable SSR (Server-Side Rendering) - default is true
  ssr: true,

  // Define aliases for easier imports
  alias: {
    '@': '/src',
  },

  // Ensure components and composables are auto-imported
  components: [
    {
      path: '~/components',
      pathPrefix: false, // Don't add 'components' prefix
    },
  ],

  imports: {
    dirs: ['stores', 'composables/**'], // Auto-import from stores and composables
  },

  compatibilityDate: '2025-04-21',
});